<template>
	<view class="shop_sell">
		<view class="main" v-if="order">
			<view class="title">商品信息</view>
			<view class="goods_info">
				<image :src="order.goods_image" mode="aspectFill"></image>
				<view class="info">
					<view class="name one-txt-cut">{{order.goods_name}}</view>
					<view class="num">
						<text class="left">￥{{order.wyy}}</text>
						<!-- <text class="right">{{order.money}}件</text> -->
					</view>
					<view class="all_money">
						<view class="left">
							<text>总价：</text>￥{{order.money}}
						</view>
						<view class="right">起订：{{config[0].num}}</view>
					</view>
				</view>
			</view>
			<view class="title_tip">出货数量</view>
			<view class="num_input">
				<u-input v-model="key" type="number" :clearable='false' placeholder='请输入' />
				<text></text>
			</view>
			<view class="title_tip">当前总件{{order.money}}</view>
			<view class="list" v-if='config'>
				<text :class="listIndex==index?'active':''" v-for="(item,index) in config" :key="index" @click="configBtn(index)">{{item.num}}{{item.txt}}</text>
				<text :class="listIndex==1000?'active':''" @click="configBtn(1000)">全部出货</text>
			</view>
		</view>
		<!--  -->
		<view class="main_info" v-if="order">
			<view class="info">
				<view class="left">出货价格</view>
				<view class="right">￥{{key}}</view>
			</view>
			<view class="info">
				<view class="left">盈利</view>
				<view class="right">￥{{money_a}}</view>
			</view>
			<view class="info">
				<view class="left">需要积分</view>
				<view class="right">{{money_b}}</view>
			</view>
		</view>
		<!-- 底部 -->
		<BottomBtn title='上架出货' @submit='submitBtn'></BottomBtn>
	</view>
</template>

<script>
	import BottomBtn from '@/components/bottom_btn/bottom_btn.vue';
	export default {
		components:{
			BottomBtn
		},
		data() {
			return {
				type:1,
				listIndex:1000,
				config:[],
				key:'',
				order:'',
				// 
			};
		},
		computed:{
			money_a(){
				if(this.key && this.order){
					return (Number(this.key)*Number(this.order.mrzf)).toFixed(2)
				}else{
					return '0.00'
				}
			},
			money_b(){
				if(this.key && this.order){
					return (Number(this.key)*Number(this.order.mrzf)*Number(this.order.jfbl)).toFixed(2)
				}else{
					return '0.00'
				}
			}
		},
		onLoad(opt) {
			this.type=opt.type
			this.chuhConfig()
		},
		methods:{
			// 出货配置
			chuhConfig(){
				var that = this
				that.$tips.showLoading('加载中')
				var params = {
					games:that.type
				}
				that.$httpApi.shipmentConfig(params).then((res)=>{
					that.$tips.hideLoading()
					if(res.code==1){
						that.order=res.data.order
						that.key=res.data.order.money
						var str=res.data.config
						for(var key in str){
							var arr = {
								num:key,
								txt:that.config[key]
							}
							that.config.push(arr)
						}
					}
				})
			},
			// 选择
			configBtn(index){
				this.listIndex=index
				if(index==1000){
					this.key=this.order.money
				}else{
					this.key=(Number(this.config[index].num)*Number(this.order.wyy)).toFixed(2)
				}
			},
			// 上架出货
			submitBtn(){
				var that = this
				uni.showModal({
					title: '提示',
					confirmColor:'#26C281',
					confirmText:'确认',
					content: '是否确认出货？',
					success: function (ress) {
						if (ress.confirm) {
							that.$tips.showLoading('加载中')
							var params = {
								games:that.type,
								type:that.listIndex==1000?1:'',
								money:Math.floor(that.key)
							}
							that.$httpApi.shipment(params).then((res)=>{
								that.$tips.hideLoading()
								if(res.code==1){
									that.$tips.showToast('出货成功')
									setTimeout(function(){
										uni.navigateTo({
											url:'/pages/shop/sell_out'
										})
									},2000)
								}
							})
						} else if (ress.cancel) {
							
						}
					}
				})
			},
		}
	}
</script>

<style lang="less">
	.shop_sell{
		width: 100%;
		padding-top: 24rpx;
		.main{
			width: 100%;
			padding: 25rpx 32rpx;
			background: #fff;
			.title{
				width: 100%;
				font-size: 32rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #222222;
			}
			.goods_info{
				width: 100%;
				padding: 32rpx 0;
				display: flex;
				image{
					display: block;
					width: 168rpx;
					height: 168rpx;
					border-radius: 10rpx;
				}
				.info{
					width: calc(100% - 168rpx);
					padding-left: 20rpx;
					height: 168rpx;
					display: flex;
					justify-content: space-between;
					flex-direction: column;
					.name{
						width: 100%;
						font-size: 32rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 500;
						color: #222222;
					}
					.num{
						width: 100%;
						display: flex;
						align-items: center;
						justify-content: space-between;
						.left{
							font-size: 28rpx;
							font-family: PingFang SC-Medium, PingFang SC;
							font-weight: 500;
							color: #222222;
						}
						.right{
							font-size: 28rpx;
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							color: #666666;
						}
					}
					.all_money{
						width: 100%;
						display: flex;
						align-items: center;
						justify-content: space-between;
						.left{
							font-size: 32rpx;
							font-family: PingFang SC-Bold, PingFang SC;
							font-weight: 500;
							color: #FF6230;
							text{
								font-size: 28rpx;
								font-family: PingFang SC-Regular, PingFang SC;
								font-weight: 400;
								color: #222222;
							}
						}
						.right{
							font-size: 28rpx;
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							color: #666666;
						}
					}
				}
			}
			.title_tip{
				width: 100%;
				padding: 24rpx 0;
				font-size: 28epx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #666666;
			}
			.num_input{
				width: 100%;
				height: 80rpx;
				padding: 0 40rpx;
				margin-bottom: 20rpx;
				border-radius: 40rpx;
				border: 2rpx solid #EBEBEB;
				display: flex;
				justify-content: space-between;
				.u-input{
					width: 90%;
				}
				text{
					line-height: 76rpx;
					font-size: 28rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #222222;
				}
			}
			.list{
				width: 100%;
				display: flex;
				flex-wrap: wrap;
				text{
					margin-bottom: 15rpx;
					margin-right: 15rpx;
					width: 160rpx;
					height: 68rpx;
					line-height: 65rpx;
					text-align: center;
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #999999;
					border: 2rpx solid #EBEBEB;
					border-radius: 34rpx;
				}
				text:nth-child(4n){
					margin-right: 0;
				}
				.active{
					color: #26C281;
					border: 2rpx solid #26C281;
				}
			}
		}
		.main_info{
			width: 100%;
			margin-top: 24rpx;
			padding: 20rpx 32rpx;
			background: #fff;
			.info{
				width: 100%;
				height: 70rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				.left{
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #999999;
				}
				.right{
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #222222;
				}
			}
		}
	}
</style>
